package com.efounder.util;

import com.efounder.constant.EnvironmentVariable;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

import static com.efounder.frame.utils.Constants.CHAT_PASSWORD;
import static com.efounder.frame.utils.Constants.CHAT_USER_ID;

/**
 * Created by yqs on 2017/2/10.
 * 现在这个类应该没什么用 20190218
 */

public class AbfragmentDataUtil {

    public static Map getParamAndValue(Hashtable menuTable) {
        Map<String, String> map = new HashMap();
        String[] paramStrings = getParams(menuTable);
        if (paramStrings != null) {
            String[] valueStrings = getValues(menuTable);
            if (valueStrings != null && valueStrings.length == paramStrings.length) {
                for (int i = 0; i < paramStrings.length; i++) {
                    map.put(paramStrings[i], valueStrings[i]);
                }
            }

        }

        return map;
    }

    public static String[] getParams(Hashtable menuTable) {
        String param = (String) menuTable.get("param");
        String[] paramStrings = null;
        if (param != null) {
            paramStrings = param.split(";");
        }
        return paramStrings;


    }

    public static String[] getValues(Hashtable menuTable) {
        String[] valueStrings = null;
        String value = (String) menuTable.get("value");
        if (value != null) {
            String[] valueSignStrings = value.split(";");
            valueStrings = new String[valueSignStrings.length];
            if (value != null) {
                for (int i = 0; i < valueSignStrings.length; i++) {

                    if (valueSignStrings[i].equals("@USERNAME@")) {
                        //valueStrings[i] = EnvironmentVariable.getProperty(CHAT_USER_ID);
                        valueStrings[i] = EnvironmentVariable.getUserName();

                    } else if (valueSignStrings[i].equals("@PASSWORD@")) {
                        valueStrings[i] = EnvironmentVariable.getProperty(CHAT_PASSWORD);

                    }
//                    else if (valueSignStrings[i].equals("@AD@")) {
//                        valueStrings[i] = EnvironmentVariable.getIsAD();
//                    }
                    else if (valueSignStrings[i].equals("@EMAIL@")) {
                        valueStrings[i] = EnvironmentVariable.getEmail();

                    } else if (valueSignStrings[i].equals("@MD5EMAIL@")) {
                        valueStrings[i] = EnvironmentVariable.getMD5Email();

                    } else if (valueSignStrings[i].equals("@MD5USERNAME@")) {
                        valueStrings[i] = EnvironmentVariable.getMD5UserID();

                    } else if (valueSignStrings[i].equals("@MD5PASSWORD@")) {
                        valueStrings[i] = EnvironmentVariable.getMD5PassWord();

                    } else if (valueSignStrings[i].equals("@MD5@")) {
                        valueStrings[i] = EnvironmentVariable.getMD5();

                    } else if (valueSignStrings[i].equals("@USERCHNAME@")) {
                        try {
                            valueStrings[i] = URLEncoder.encode(EnvironmentVariable.getUserName(), "utf-8");
                        } catch (UnsupportedEncodingException e) {

                            e.printStackTrace();
                        }
                        // EnvironmentVariable.getUserName();
                    } else if (valueSignStrings[i].endsWith("@username@")) {
                        valueStrings[i] = EnvironmentVariable.getProperty(CHAT_USER_ID);
                        //    else if (valueSignStrings[i].endsWith("usernamenew")) {
//                        paramStrings[i]="username";
//                        valueStrings[i] = EnvironmentVariable.getUserNameNew();
//                    }else if(valueSignStrings[i].endsWith("usernamemail")){
//                        paramStrings[i]="username";
//                        valueStrings[i] = EnvironmentVariable.getUserNameMail();
//                    }else if(valueSignStrings[i].endsWith("@password@")){
//                        valueStrings[i] = EnvironmentVariable.getProperty(CHAT_PASSWORD);
//                        userPwd = EnvironmentVariable.getProperty(CHAT_PASSWORD);
//                        continue;
//                    }
                    } else if (valueSignStrings[i].endsWith("@chuser@")) {
//                        valueStrings[i] = EnvironmentVariable.getUserName();
//                    }
//
//

                    }

                }
            }

        }
        return valueStrings;
    }
}
